package o;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import androidx.annotation.NonNull;
import androidx.core.view.ViewCompat;
import java.lang.reflect.Method;
import java.util.ArrayList;

class ob implements og {
    protected c ˋ;

    static class c extends ViewGroup {
        static Method ˎ;
        View ˊ;
        ViewGroup ˋ;
        ob ˏ;
        ArrayList<Drawable> ॱ = null;

        static {
            try {
                ˎ = ViewGroup.class.getDeclaredMethod("invalidateChildInParentFast", new Class[]{Integer.TYPE, Integer.TYPE, Rect.class});
            } catch (NoSuchMethodException e) {
            }
        }

        c(Context context, ViewGroup viewGroup, View view, ob obVar) {
            super(context);
            this.ˋ = viewGroup;
            this.ˊ = view;
            setRight(viewGroup.getWidth());
            setBottom(viewGroup.getHeight());
            viewGroup.addView(this);
            this.ˏ = obVar;
        }

        public boolean dispatchTouchEvent(MotionEvent motionEvent) {
            return false;
        }

        public void ॱ(Drawable drawable) {
            if (this.ॱ == null) {
                this.ॱ = new ArrayList();
            }
            if (!this.ॱ.contains(drawable)) {
                this.ॱ.add(drawable);
                invalidate(drawable.getBounds());
                drawable.setCallback(this);
            }
        }

        public void ˋ(Drawable drawable) {
            if (this.ॱ != null) {
                this.ॱ.remove(drawable);
                invalidate(drawable.getBounds());
                drawable.setCallback(null);
            }
        }

        protected boolean verifyDrawable(@NonNull Drawable drawable) {
            return super.verifyDrawable(drawable) || (this.ॱ != null && this.ॱ.contains(drawable));
        }

        public void ॱ(View view) {
            if (view.getParent() instanceof ViewGroup) {
                ViewGroup viewGroup = (ViewGroup) view.getParent();
                if (!(viewGroup == this.ˋ || viewGroup.getParent() == null || !ViewCompat.ˋˊ(viewGroup))) {
                    int[] iArr = new int[2];
                    int[] iArr2 = new int[2];
                    viewGroup.getLocationOnScreen(iArr);
                    this.ˋ.getLocationOnScreen(iArr2);
                    ViewCompat.ॱॱ(view, iArr[0] - iArr2[0]);
                    ViewCompat.ʽ(view, iArr[1] - iArr2[1]);
                }
                viewGroup.removeView(view);
                if (view.getParent() != null) {
                    viewGroup.removeView(view);
                }
            }
            super.addView(view, getChildCount() - 1);
        }

        public void ˎ(View view) {
            super.removeView(view);
            if (ˏ()) {
                this.ˋ.removeView(this);
            }
        }

        boolean ˏ() {
            return getChildCount() == 0 && (this.ॱ == null || this.ॱ.size() == 0);
        }

        public void invalidateDrawable(@NonNull Drawable drawable) {
            invalidate(drawable.getBounds());
        }

        protected void dispatchDraw(Canvas canvas) {
            int[] iArr = new int[2];
            int[] iArr2 = new int[2];
            this.ˋ.getLocationOnScreen(iArr);
            this.ˊ.getLocationOnScreen(iArr2);
            canvas.translate((float) (iArr2[0] - iArr[0]), (float) (iArr2[1] - iArr[1]));
            canvas.clipRect(new Rect(0, 0, this.ˊ.getWidth(), this.ˊ.getHeight()));
            super.dispatchDraw(canvas);
            int size = this.ॱ == null ? 0 : this.ॱ.size();
            for (int i = 0; i < size; i++) {
                ((Drawable) this.ॱ.get(i)).draw(canvas);
            }
        }

        protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
        }

        private void ˊ(int[] iArr) {
            int[] iArr2 = new int[2];
            int[] iArr3 = new int[2];
            this.ˋ.getLocationOnScreen(iArr2);
            this.ˊ.getLocationOnScreen(iArr3);
            iArr[0] = iArr3[0] - iArr2[0];
            iArr[1] = iArr3[1] - iArr2[1];
        }

        public ViewParent invalidateChildInParent(int[] iArr, Rect rect) {
            if (this.ˋ != null) {
                rect.offset(iArr[0], iArr[1]);
                if (this.ˋ instanceof ViewGroup) {
                    iArr[0] = 0;
                    iArr[1] = 0;
                    int[] iArr2 = new int[2];
                    ˊ(iArr2);
                    rect.offset(iArr2[0], iArr2[1]);
                    return super.invalidateChildInParent(iArr, rect);
                }
                invalidate(rect);
            }
            return null;
        }
    }

    ob(Context context, ViewGroup viewGroup, View view) {
        this.ˋ = new c(context, viewGroup, view, this);
    }

    static ViewGroup ˊ(View view) {
        View view2 = view;
        while (view2 != null) {
            if (view2.getId() == 16908290 && (view2 instanceof ViewGroup)) {
                return (ViewGroup) view2;
            }
            if (view2.getParent() instanceof ViewGroup) {
                view2 = (ViewGroup) view2.getParent();
            }
        }
        return null;
    }

    static ob ˋ(View view) {
        ViewGroup ˊ = ˊ(view);
        if (ˊ == null) {
            return null;
        }
        int childCount = ˊ.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View childAt = ˊ.getChildAt(i);
            if (childAt instanceof c) {
                return ((c) childAt).ˏ;
            }
        }
        return new ny(ˊ.getContext(), ˊ, view);
    }

    public void ˊ(@NonNull Drawable drawable) {
        this.ˋ.ॱ(drawable);
    }

    public void ˎ(@NonNull Drawable drawable) {
        this.ˋ.ˋ(drawable);
    }
}
